class Admin::ApsController < Admin::ApplicationController
  def index
    @aps = Ap.all
  end

  def edit
    @aps = Ap.find(params[:id])
    @aps_message = ''
  end

  def show
    @aps = Ap.find(params[:id])
    @aps_message = ''
    render 'edit'
  end

  def update
    @aps = Ap.find(params[:id])
    if params[:file]
      @aps.image = params[:file]
    end
    @aps.update( aps_params )
    @aps_message = '广告更新成功！'
    render 'edit'
  end

  def new
  end

  def create
    @aps = Ap.new( aps_params )
    if @aps.save
      @aps_message = '广告添加成功！!'
    else
      @aps_message = '广告添加失败！!'
    end

    render 'edit'
  end

  private
  def aps_params
    params.permit(:title, :url, :image, :cities, :place, :sort, :isopen)
  end

end
